package com.hq.fxh.No3_TuiGuang.Adaoter;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.hq.fxh.HttpApi.ArticleServiceImpl;
import com.hq.fxh.Intefers.NetworkSubscriber;
import com.hq.fxh.Modle.RankBean;
import com.hq.fxh.No0_ChengQu.Login.LoginActivity;
import com.hq.fxh.No3_TuiGuang.MyMoBan.Activity.item.ToastUtils;
import com.hq.fxh.No3_TuiGuang.MyMoBan.Model.CommonRes;
import com.hq.fxh.R;
import com.hq.fxh.Utils.IntentUtils;

import java.io.Serializable;
import java.util.List;

import static android.R.attr.data;
import static cn.jiguang.analytics.android.api.JAnalyticsInterface.mContext;
import static cn.jpush.im.android.tasks.GetUserInfoListTask.IDType.uid;

/**
 * /**
 *
 * @author 薛
 * @ClassName
 * @Description :
 * @Created 2017/10/9
 * @Email xlwenhao1858@sina.com
 */


public class Ladapter_HotNews extends BaseAdapter {

    private List<RankBean> mDatas;

    public Ladapter_HotNews(List<RankBean> mDatas) {
        this.mDatas = mDatas;
    }

    @Override
    public int getCount() {
        return mDatas == null ? 0 : mDatas.size();
    }

    @Override
    public Object getItem(int i) {
        return mDatas.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = convertView;
        ViewHolder viewHolder = null;
        if (view == null || !(view.getTag() instanceof ViewHolder)) {
            view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_hotnew, null);
            viewHolder = new ViewHolder(view);
            view.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }
        RankBean data = mDatas.get(position);
        viewHolder.rank.setText(position + 1 + "");
        viewHolder.title.setText(data.getTitle());
        String nickname = data.getNickname();
        if (nickname.length() > 10) {
            nickname = nickname.substring(0, 10);
        }
        viewHolder.name.setText(nickname);
        viewHolder.count.setText(data.getLook_num() + "次曝光  " + data.getTrans_num() + "次转发");

        return view;
    }


    static class ViewHolder {
        protected TextView rank;
        protected TextView title;
        protected TextView name;
        protected TextView count;

        ViewHolder(View rootView) {
            initView(rootView);
        }

        private void initView(View rootView) {
            rank = (TextView) rootView.findViewById(R.id.rank);
            title = (TextView) rootView.findViewById(R.id.title);
            name = (TextView) rootView.findViewById(R.id.name);
            count = (TextView) rootView.findViewById(R.id.count);
        }
    }
}
